<script type="text/javascript">
$(function () {
	$.ajaxSetup({cache: false});
});

function saveOrganTypeHandle() {
	var handleList = '';
	$('input[type="checkbox"]').each(function() {
		if ($(this).prop('checked'))
			handleList += $(this).attr('id') + ',';
	});
	$('input[handleType="hidden"]').each(function() {
		if ($(this).prop('checked'))
			handleList += $(this).attr('id') + ',';
	});
	var parm = {'code':'${code}', 'handleList':handleList.substring(0, handleList.length - 1)};
	var url = create_url('organType-saveHandle');
	sys_submiting();
	$.ajax({type:'POST', url:url, data:parm,
		success : function(result) {
			sys_submiting_close();
			if (result == 'success') {
				sys_msg('操作成功!');
				organType_queryOrganType();
				$.fn.colorbox.close();
			} else {
				sys_warning('操作失败!');
			}
		}
	});
}

//选择操作
function selectedOrganType(cbCode) {
	var cb = $('#' + cbCode);
	$('input[parentCode="' + cbCode + '"]').each(function(e) {
		
		if (cb.attr('checked') == 'checked' || cb.attr('checked') || cb.prop('checked'))
			$(this).attr('checked', 'checked');
		else 
			$(this).removeAttr('checked');

		selectedOrganType($(this).attr('id'));
	});

	if (cb.prop('checked')) {
		var parentCb = $('#' + cb.attr('parentCode'));
		while (true) {
			if (null == parentCb || 'undefined' == parentCb || '' == parentCb.attr('id') || null == parentCb.attr('id'))
				break;
			parentCb.prop('checked', true);
			parentCb = $('#' + parentCb.attr('parentCode'));
		}
	} else {
		var flag = true;
		var parentCode = cb.attr('parentCode');
		while (true) {
			if (null == parentCode || '' == parentCode)
				break;

			$('input[parentCode="' + parentCode + '"]').each(
				function() {
					if ($(this).prop('checked'))
						flag = false;
			});
			if (flag) {
				$('#' + parentCode).prop('checked', false);
				parentCode = $('#' + parentCode).attr('parentCode');
			} else {
				break;
			}
		}
	}
}


function showOrHide(btn, div) {
	$('#' + div).slideToggle("slow");
}
</script>

<a class="btn btn-info" href="javascript:;" onclick="javascript:saveOrganTypeHandle();" style="margin:5px 0 5px 0"><i class="fontello-icon-floppy"></i> 保存机构类型可进行对应的操作</a>
<#list menu as sys>
<div class="panelHead">
	<input type="checkbox" id="${sys.code}" onclick="javascript:selectedOrganType('${sys.code}');"<#if (handleMap?? && handleMap[sys.code]??)> checked="checked"</#if> />
	<a href="javascript:;" onclick="javascript: showOrHide($(this), 'div_${sys.code}');">${sys.name}</a>
	<span style="float:right; font-size:12px; font-weight:normal;">
		<a href="javascript:;" onclick="javascript:showOrHide($(this), 'div_${sys.code}');">展开 / 隐藏</a>
	</span>
</div>
<div id="div_${(sys.code)!''}" style="display:none;">
	<#list sys.moduleList as mo>
	<div class="panelContent" style="margin-left:15px;">
	<input type="checkbox" id="${mo.code}" parentCode="${sys.code}" onclick="javascript:selectedOrganType('${mo.code}');"<#if (handleMap?? && handleMap[mo.code]??)> checked="checked"</#if> /> 
	<a href="javascript:;" onclick="javascript: showOrHide($(this), 'div_${mo.code}');">${mo.name}</a>
		<#list mo.menuList as me>
		<div style="border-bottom:1px dashed #ccc;padding:10px 0">
			<p style="width:600px;float:left;line-height:20px;font-weight: bold;margin-left:15px;">
				<input type="checkbox" id="${me.code}" parentCode="${mo.code}" onclick="javascript:selectedOrganType('${me.code}')"<#if (handleMap?? && handleMap[me.code]??)> checked="checked"</#if> />
				${me.name}(${me.des})
			</p>
			&nbsp;
			<p style="line-height:20px; width:600px;margin-left:25px;">
				<#list me.handleList as h> <#if !(h.hide)> 
				<input type="checkbox" id="${h.code}" parentCode="${me.code}" onclick="javascript:selectedOrganType('${h.code}')"<#if (handleMap?? && handleMap[h.code]??)> checked="checked"</#if> />
				&nbsp;${h.name}&nbsp;&nbsp;
				<#else> 
				<input type="hidden" id="${h.code}" parentCode="${me.code}" handleType="hidden" onclick="selectedOrganType(this.id)"<#if (handleMap?? && handleMap[h.code]??)> checked="checked"</#if> />
				</#if>
				</#list>
			</p>
		</div>
		</#list>
	</div>
	</#list>
</div>
</#list>
<a class="btn btn-info" href="javascript:;" onclick="javascript:saveOrganTypeHandle();" style="margin:5px 0 5px 0"><i class="fontello-icon-floppy"></i> 保存机构类型可进行对应的操作</a>

